<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="结算时间">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.settleTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.settleTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="下单时间">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.orderTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.orderTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单号">
              <j-input placeholder="请输入订单号" v-model="queryParam.orderNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结算状态">
              <j-dict-select-tag v-model="queryParam.status" dictCode="fund_log_status" placeholder="全部" clearable />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download" @click="handleExportXls('订单明细')" style="margin-left: 8px">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" rowKey="id" :columns="queryParam.supplierId ? columnsSupplier : columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="addSlot" slot-scope="text">
          <span>+{{text}}</span>
        </template>
        <template slot="subtractionSlot" slot-scope="text">
          <span>-{{text}}</span>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
      </a-table>
    </div>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import JInput from '@/components/jeecg/JInput'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import Vue from "vue"
import { ORG_CODE, SHOP_TYPE } from "@/store/mutation-types"
import { getAction } from '@/api/manage'

export default {
  name: 'RmsOrderLogList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    JInput,
    JSearchSelectTag
  },
  data () {
    return {
      description: '订单明细',
      // 表头
      columns: [
        {
          title: '订单号',
          align: "center",
          dataIndex: 'orderNo'
        },
        {
          title: '下单时间',
          align: "center",
          dataIndex: 'orderTime'
        },
        {
          title: '实付金额',
          align: "center",
          dataIndex: 'amount'
        },
        {
          title: '余额支付',
          align: "center",
          dataIndex: 'balanceDiscount'
        },
        {
          title: '平台服务费',
          align: "center",
          dataIndex: 'platformServiceAmount',
          scopedSlots: { customRender: "subtractionSlot" }
        },
        {
          title: '营销补偿',
          align: "center",
          dataIndex: 'discount',
          scopedSlots: { customRender: "addSlot" }
        },
        {
          title: '分销费用',
          align: "center",
          dataIndex: 'distributionAmount',
          scopedSlots: { customRender: "subtractionSlot" }
        },
        {
          title: '结算金额  ',
          align: "center",
          dataIndex: 'shopSettleAmount'
        },
        {
          title: '结算状态',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '结算时间',
          align: "center",
          dataIndex: 'settleTime'
        },
      ],
      columnsSupplier: [
        {
          title: '订单号',
          align: "center",
          dataIndex: 'orderNo'
        },
        {
          title: '下单时间',
          align: "center",
          dataIndex: 'orderTime'
        },
        {
          title: '供货金额',
          align: "center",
          dataIndex: 'supplyAmount'
        },
        {
          title: '结算金额  ',
          align: "center",
          dataIndex: 'supplierSettleAmount'
        },
        {
          title: '结算状态',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '结算时间',
          align: "center",
          dataIndex: 'settleTime'
        },
      ],
      url: {
        list: "/rms/rmsOrderLog/list",
        delete: "/rms/rmsOrderLog/delete",
        deleteBatch: "/rms/rmsOrderLog/deleteBatch",
        exportXlsUrl: "/rms/rmsOrderLog/exportXls",
        importExcelUrl: "rms/rmsOrderLog/importExcel",
      },
      choiceDate: undefined,
      dictOptions: {},
      /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
      queryParam: {
        supplierId: undefined,
        shopId: undefined,
      },
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig () {
    },
    initParam () {
      //当前用户店铺类型1:平台，2：自营，3：店铺，4：供应商
      if (this.queryParam.shopId === undefined
        && this.queryParam.supplierId === undefined) {
        let type = this.$route.query.type ? this.$route.query.type : Vue.ls.get(SHOP_TYPE)
        let shopId = this.$route.query.id ? this.$route.query.id : Vue.ls.get(ORG_CODE)
        if (type == 4) {
          this.queryParam.supplierId = shopId
        } else {
          this.queryParam.shopId = shopId
        }
      }
    },
    loadData (arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }

      this.initParam()
      var params = this.getQueryParams()//查询条件

      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
          this.onClearSelected()
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>